# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=cgal
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=6.0.1
pkgrel=1
pkgdesc="Computational Geometry Algorithms Library (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://www.cgal.org/"
msys2_repository_url="https://github.com/CGAL/cgal"
msys2_references=(
  "cpe: cpe:/a:cgal:computational_geometry_algorithms_library"
)
license=("spdx:CC0-1.0 AND BSL-1.0 AND MIT AND LGPL-3.0-or-later AND GPL-3.0-or-later")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-ninja")
depends=("${MINGW_PACKAGE_PREFIX}-boost"
         "${MINGW_PACKAGE_PREFIX}-eigen3"
         "${MINGW_PACKAGE_PREFIX}-gmp"
         "${MINGW_PACKAGE_PREFIX}-mpfr")
optdepends=("${MINGW_PACKAGE_PREFIX}-qt6-svg: for CGAL_Qt6"
            "${MINGW_PACKAGE_PREFIX}-qt6-script: for CGAL_Qt6"
            "${MINGW_PACKAGE_PREFIX}-tbb: for some packages, see the CGAL manual")
source=(https://github.com/CGAL/cgal/releases/download/v${pkgver}/CGAL-${pkgver}.tar.xz)
sha256sums=('0acdfbf317c556630dd526f3253780f29b6ec9713ee92903e81b5c93c0f59b7f')

build() {
  mkdir -p "${srcdir}"/build-${MSYSTEM} && cd "${srcdir}"/build-${MSYSTEM}

  declare -a _extra_config
  if check_option "debug" "n"; then
    _extra_config+=("-DCMAKE_BUILD_TYPE=Release")
  else
    _extra_config+=("-DCMAKE_BUILD_TYPE=Debug")
  fi

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake \
      -G"Ninja" \
      -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
      "${_extra_config[@]}" \
      -DCGAL_ENABLE_TESTING=OFF \
      ../CGAL-${pkgver}

  ${MINGW_PREFIX}/bin/cmake --build .
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"

  DESTDIR="${pkgdir}" ${MINGW_PREFIX}/bin/cmake --install .

  install -Dm644 $srcdir/CGAL-${pkgver}/LICENSE -t "$pkgdir${MINGW_PREFIX}"/share/licenses/${_realname}
  install -Dm644 $srcdir/CGAL-${pkgver}/LICENSE.* -t "$pkgdir${MINGW_PREFIX}"/share/licenses/${_realname}
  install -Dm644 $srcdir/CGAL-${pkgver}/LICENSES/* -t "$pkgdir${MINGW_PREFIX}"/share/licenses/${_realname}
}
